package CommonGui;

import java.awt.Color;
import java.awt.Component;
import java.util.Date;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class ColorRowRendererForTelOrder extends DefaultTableCellRenderer 
{
	   Color bkgndColor, fgndColor;
	 	
	   public ColorRowRendererForTelOrder() {
	      setOpaque(true);      
	   }
	  	
	   public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) 
	   {
		   String orderTime=(String)(((Vector) ((MyTableModelForTelOrdersJTable)table.getModel()).getDataVector().get(row)).get(0));
		   String orderStatus=(String)(((Vector) ((MyTableModelForTelOrdersJTable)table.getModel()).getDataVector().get(row)).get(5));
		   Date date = new Date();
		   int currHour=date.getHours();
		   int currMinuts=date.getMinutes();
		   int orderHour=Integer.parseInt(orderTime.substring(0, 2));
		   int orderMinuts=Integer.parseInt(orderTime.substring(3, 5));
		   Component cell;
		   Component cell2;
		   Color rowColor=new Color(255, 250, 205);
		    
		   if(((currHour>orderHour)||(currHour==orderHour && currMinuts>orderMinuts))&&(orderStatus.equals("פתוח")))
		   {
		   rowColor=Color.red;
		   }
		   
		   else
		   {
			   rowColor=new Color(255, 250, 205);
		   }
		   
		   if(isSelected) {  
	            super.setForeground(table.getSelectionForeground());  
	            super.setBackground(table.getSelectionBackground());  
	        } else {  
	            super.setForeground(Color.black);     
	            super.setBackground(rowColor);  
	        }     
		   	   
		   setFont(table.getFont());                                  
	       setValue(value);  
		   return this;
	      
	   }
	}